//
//  PBContractDetailController.m
//  PBHomeDemo
//
//  Created by Playboy on 2018/3/19.
//  Copyright © 2018年 tmkj. All rights reserved.
//

#import "PBContractDetailController.h"
#import "PBCountDetailController.h"

@interface PBContractDetailController ()
@property (strong, nonatomic) IBOutlet UIImageView *coverImageView;
@property (strong, nonatomic) IBOutlet UILabel *mainLabel;
@property (strong, nonatomic) IBOutlet UILabel *priceLabel;
@property (strong, nonatomic) IBOutlet UILabel *bigLabel;
@property (strong, nonatomic) IBOutlet UILabel *typeLabel;
@property (strong, nonatomic) IBOutlet UILabel *rentLabel;
@property (strong, nonatomic) IBOutlet UILabel *yaLabel;
@property (strong, nonatomic) IBOutlet UILabel *sumLabel;
@property (strong, nonatomic) IBOutlet UILabel *nameLabel;
@property (strong, nonatomic) IBOutlet UILabel *idCardLabel;
@property (strong, nonatomic) IBOutlet UILabel *dateLabel;

@end

@implementation PBContractDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self configure];
}
- (void)configure {
    [self configureView];
    [self configureData];
}

- (void)configureView {
    NSDictionary *param = @{};
    [TMNetwork requestGetWithParam:param url:@"/user/identifyCard/get" callback:^(TMBaseReqModel *model) {
        if (model.code == 200) {
            self.nameLabel.text = model.data[@"realName"];
            self.idCardLabel.text = model.data[@"identifyCardNum"];
        }else {
            [self showHint:model.message];
        }
    }];
}
- (void)configureData {
    [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:self.model.cover] placeholderImage:nil];
    self.mainLabel.text = self.model.name;
    self.priceLabel.text = [NSString stringWithFormat:@"%@元/月",self.model.rent];
    self.bigLabel.text = [NSString stringWithFormat:@"%@㎡",self.model.area];
    self.rentLabel.text = [NSString stringWithFormat:@"¥%@元",self.model.rent];
    self.yaLabel.text = [NSString stringWithFormat:@"¥%@元",self.model.rent];
    self.sumLabel.text = [NSString stringWithFormat:@"¥%@元",self.payModel.price];
    self.typeLabel.text = [NSString stringWithFormat:@"支付方式：%@",self.payModel.name];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"YYYY-MM-dd";
    // 数字时间戳转化为日期，如果为13位，则需要除以1000，或者去掉后3位
    NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:[[self.model.contractStart substringWithRange:NSMakeRange(0, 10)] doubleValue]];
    NSString *startTime = [formatter stringFromDate:startDate];
    NSDate *endDate = [NSDate dateWithTimeIntervalSince1970:[[self.model.contractEnd substringWithRange:NSMakeRange(0, 10)] doubleValue]];
    NSString *endTime = [formatter stringFromDate:endDate];
    self.dateLabel.text = [NSString stringWithFormat:@"%@至%@",startTime,endTime];
}

// 提交合同
- (IBAction)sureButtonClick:(id)sender {
    PBCountDetailController *vc = [[PBCountDetailController alloc] init];
    vc.model = self.model;
    vc.payModel = self.payModel;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - super
- (void)resetNavigationBarItems {
    [super resetNavigationBarItems];
    self.title = @"提交合同";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
